<?php
/*

CREATE TABLE `domain7` (
  `id` int(11) NOT NULL auto_increment,
  `k` varchar(20) NOT NULL,
  `com` tinyint(1) NOT NULL,
  `cn` tinyint(1) NOT NULL,
  `net` tinyint(1) NOT NULL,
  `lenth` tinyint(4) NOT NULL,
  `timeline` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  PRIMARY KEY  (`id`),
  KEY `k` (`k`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8

*/
include 'Db.class.php';
$db = new Db('localhost','root','root','test');
$url = 'http://ajaxwhois.com/lookup?d=';
$url2 = 'http://panda.www.net.cn/cgi-bin/check.cgi?area_domain=';
$num=0;
$ch = curl_init(); 


while (true){

	$num++;
	$firstN = 'net'.$num;
	$sql = "SELECT * FROM domain7 WHERE `k` = '$firstN'";
	if ($db->getRow($sql)) continue;		
	$sql = "INSERT INTO domain7 (`k`,`lenth`) VALUES ('$firstN','".strlen($firstN)."')";
	$db->query($sql);	
	echo "get $firstN \r\n";
	$domain1 = $firstN.'.com';			
	$domain2 = $firstN.'.cn';
	
	 	
	
	$urls = $url2.$domain1;	
	$res = file_get_contents($urls); 	
	if (preg_match('/original\>210/',$res)){
		echo $domain2." can reg \n";
		$sql = "UPDATE domain7 SET `com` = 1 WHERE `k` LIKE '$firstN'";
		$db->query($sql);
	}

	$urls = $url2.$domain2;
	$res = file_get_contents($urls); 
	if (preg_match('/original\>210/',$res)){
		echo $domain2." can reg \n";
		$sql = "UPDATE domain7 SET `cn` = 1 WHERE `k` LIKE '$firstN'";
		$db->query($sql);
	}

	
	$m =  memory_get_usage();
	print_r('use mem: '.($m/1000).' kb');
	echo "\r\n";
	if($num%500==0){
		curl_close($ch);
		unset($ch);
		unset($db);
		echo "sleeping.............................................\r\n";
		sleep(5);
		$db = new Db('localhost','root','','test');	
		$ch = curl_init(); 
	}
	echo "\r\n";
	echo "\r\n";
	unset($m);
	unset($res);
	unset($domain1);
	unset($domain2);
	unset($firstN);

}
?>
